You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
新增测试覆盖 A2A_TASK_STORE_CREATE_TABLE=false 时不自动创建 state tables。
删除了只服务测试的生产 helper close_task_store()。
测试改为直接释放 task store 持有的 engine。
补充验证:
uv run pre-commit run --all-files
uv run pytest
结果:357 passed
新增 commit:
8a5889dfix(server): align database state tables with create-table config (#304)
liujuanjuan1984
changed the title
feat(server): add database-backed persistence for task and runtime state
feat(server): add database-backed stores for task and runtime state
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
实现
#304:为服务引入可配置的 database-backed task store,并将跨重启仍需保留的 session / interrupt runtime state 收口到同一持久化后端。改动模块
1. 配置与依赖
pyproject.tomluv.locksrc/opencode_a2a/config.py新增:
A2A_TASK_STORE_BACKENDA2A_TASK_STORE_DATABASE_URLA2A_TASK_STORE_TABLE_NAMEA2A_TASK_STORE_CREATE_TABLEA2A_PENDING_SESSION_CLAIM_TTL_SECONDS补充
sqlalchemy/aiosqlite依赖,并在A2A_TASK_STORE_BACKEND=database时要求显式提供 database URL。说明:
A2A_TASK_STORE_CREATE_TABLE统一控制 task table 与 runtime state tables 的自动创建。A2A_PENDING_SESSION_CLAIM_TTL_SECONDS为 preferred session claim 提供显式租约时长,避免异常退出后的长期阻塞。2. App 装配与 Task Store
src/opencode_a2a/server/task_store.pysrc/opencode_a2a/server/application.py新增 task store builder,按配置选择:
InMemoryTaskStoreDatabaseTaskStore在 app lifespan 中统一初始化 task store / state repository,并在退出时释放 shared database engine。
3. Session / Interrupt 状态持久化
src/opencode_a2a/runtime_state.pysrc/opencode_a2a/server/state_store.pysrc/opencode_a2a/execution/session_manager.pysrc/opencode_a2a/opencode_upstream_client.pysrc/opencode_a2a/execution/stream_runtime.pysrc/opencode_a2a/jsonrpc/application.pysrc/opencode_a2a/execution/executor.py新增 repository 抽象与 memory/database 双后端,接入:
修正:
(identity, context_id) -> session_id绑定,不再残留内存分支调用。SessionManager不再暴露_sessions/_session_owners/_pending_session_claims这组 memory alias,避免后续继续误把内存后端当成权威状态源。4. Contract、文档与测试
src/opencode_a2a/contracts/extensions.pydocs/guide.mdtests/server/test_task_store_factory.pytests/server/test_state_store.pytests/server/test_database_app_persistence.pytests/execution/test_session_ownership.py新增覆盖:
A2A_TASK_STORE_CREATE_TABLE=false时不自动创建 state tables对齐:
(identity, contextId) -> session_id固定描述成 memory-only。当前边界
仍保持进程内状态,不进入数据库:
验证
./scripts/doctor.sh361 passed相关 commits
10573d5feat(server): add database-backed task store backend (#304)e51bc97feat(server): persist session and interrupt state in database backend (#304)3328523test(server): cover app restart persistence for database backend (#304)8a5889dfix(server): align database state tables with create-table config (#304)9c8cb63fix(server): harden preferred session claim persistence (#304)11203d7fix(contracts): remove stale memory-store assumptions (#304)Issue 关联
Closes #304
Relates to #264
说明:本 PR 直接落地
#304的 durability 主诉求;对#264属于母单下的相关演进项,因此保持Relates to更准确。